#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <list>
using namespace std;

int main()
{
	int n; cin >> n;
	list<int> l;
	while (n--)
	{
		int tmp; cin >> tmp;
		l.push_back(tmp);
	}
	int i, val, jug = 0;
	while (scanf(" %d %d", &i, &val) == 2)
	{
		if (jug) cout << endl; jug = 1;
		if (i <= 0 || i > l.size() + 1) cout << "invalid";
		else
		{
			auto it = l.begin();
			advance(it, i - 1);
			l.insert(it, val);
			cout << "head-->";
			for (const auto& e : l) cout << e << "-->";
			cout << "tail";
		}
	}
	return 0;
}